#ifndef CUBE_H
#define CUBE_H

#include <algorithm>

struct Cube
{
	// (x, y, z) bottom_leftfront coordinates
    int length, width, height, x, y, z, cnt;
	Cube() {}
	Cube(int _length, int _width, int _height)
		: length(_length), width(_width), height(_height), cnt(0) {}
	Cube(int _length, int _width, int _height, int _x, int _y, int _z)
		: length(_length), width(_width), height(_height), x(_x), y(_y), z(_z), cnt(0) {}
	
	int GetVolume()
	{
		return length * width * height;
	}
	
	void SetPos (int _x, int _y, int _z)
	{
		x = _x; y = _y; z = _z;
	}

	void rotate() {
		int zz = z; 
		z = y; y = x; x = zz;
		if (++cnt > 3) {
			std::swap(y, z); cnt = 0;
		}
	}
	bool intersect_y_z(const Cube &o)
	{
		return !(o.z >= z + height || o.z + o.height <= z) && !(o.y >= y + width || o.y + o.width <= y);
	}
	
	bool intersect(const Cube &o)
	{
		return !(o.x >= x + length || o.x + o.length <= x) && 
			   !(o.y >= y + width || o.y + o.width <= y) &&
			   !(o.z >= z + height || o.z + o.height <= z);
	}

	bool operator < (const Cube & o) {
		if (x != o.x) return x < o.x;
		if (y != o.y) return y < o.y;
		return z < o.z;
	}

};

#endif /* CUBE_H */
